home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9103 / lastlog / mygroups.c < prev    next >
C/C++ Source or Header  |  1991-02-10  |  2KB  |  79 lines

  1. /*****************************************************************
  2. *  MyGroups.C
  3. *  written by Kathy Cea, Platinum Software Int'l.
  4. *
  5. *  Lists all the groups to which the user belongs.
  6. *
  7. *  Calling Syntax:
  8. *     MyGroups
  9. *
  10. *  Compiled in Turbo C 2.0 with NetWare C function calls
  11. *****************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <nit.h>
  16. #include <niterror.h>
  17. #define NO 0
  18. #define YES 1
  19.  
  20. main() {
  21.     WORD ConnectNumber;
  22.     BYTE loginTime[7];
  23.     long objectId;
  24.     WORD objectType;
  25.     char objectName[48],
  26.          groupName[48];
  27.     BYTE propertyValue[128];
  28.     BYTE moreSegs,
  29.          propertyFlag;
  30.     int segNum;
  31.     BYTE temp[3];
  32.     BYTE holdobjId[9];
  33.     char *endptr;
  34.     int i,j,done;
  35.  
  36.     segNum = 1;
  37.     moreSegs = 255;
  38.  
  39.     /* Get the current connection number */
  40.     ConnectNumber = GetConnectionNumber();
  41.  
  42.     /* Get the Object Name and Object Type */
  43.     GetConnectionInformation(ConnectNumber, objectName,
  44.             &objectType, &objectId, loginTime);
  45.  
  46.     printf("Groups I'm in:\n");
  47.  
  48.     /* Read the GROUP_I'M_IN property set until no more groups */
  49.     while (moreSegs) {
  50.        ReadPropertyValue(objectName, OT_USER, "GROUPS_I'M_IN", segNum,
  51.              propertyValue, &moreSegs, &propertyFlag);
  52.  
  53.         segNum++;
  54.         /* Convert each 4-byte value into a long Object ID */
  55.         i = 0;
  56.         temp[2] = '\0';
  57.         holdobjId[0] = '\0';
  58.         done = NO;
  59.         while (i < 128 && !done) {
  60.             for (j=0; j < 4; j++) {
  61.                 sprintf(temp, "%02x", propertyValue[i]);
  62.                 temp[2] = '\0';
  63.                 strcat(holdobjId, temp);
  64.                 i++;
  65.             } /* for */
  66.             objectId = strtoul(holdobjId, &endptr, 16);
  67.             if (objectId == 0)
  68.                 done = YES;
  69.             else {
  70.                 /* Now that we have the Object ID, get the Group Name */
  71.                 GetBinderyObjectName(objectId, groupName, &objectType);
  72.                 printf("%s\n",groupName);
  73.                 holdobjId[0] = '\0';
  74.              } /* else */
  75.         } /* while (i < 128) */
  76.     } /* while (moreSegs) */
  77. } /* main */
  78.  
  79.